# @Version        : 1.0
# @Update Time    : 2024/9/10 21:30
# @File           : dept_schema.py
# @IDE            : PyCharm
# @Desc           : 文件描述信息
from typing import Optional, Literal, Annotated
from pydantic import Field
from src.schemas.base_schema import MixinSchema, custom_error_msg
from fastapi_utils.api_model import APIModel
from fastapi import Depends
from src.core.dependencies import QueryParams, Paging


class DeptParams(QueryParams):
    def __init__(
        self,
        params: Paging = Depends(Paging),
    ):
        super().__init__(params)


class DeptCreate(APIModel):
    # model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)
    dept_name: Annotated[
        str,
        Field(description="部门名称", min_length=1),
        custom_error_msg("部门名称不能为空"),
    ]
    parent_id: Optional[int] = Field(None, description="父级ID")
    order_num: int = Field(..., description="排序")
    ancestors: Optional[str] = Field(None, description="祖级列表")
    leader: Optional[str] = Field(None, description="部门领导")
    phone: Optional[str] = Field(None, description="电话")
    status: Literal["1", "2"] = Field(default="1", description="是否启用1:启用，2:禁用")
    remark: Optional[str] = Field(None, description="描述")


class DeptUpdate(DeptCreate):
    id: int = Field(..., description="部门ID")


class DeptOut(MixinSchema, DeptCreate):
    pass


class DeptTree(DeptOut):
    children: list["DeptTree"] | None = None
